package org.example.sportdemo.controller;

import org.example.sportdemo.entity.GroundOrder;
import org.example.sportdemo.entity.GroundPreserve;
import org.example.sportdemo.service.GroundOrderService;
import org.example.sportdemo.service.GroundPreserveService;
import org.example.sportdemo.utils.PageUtils;
import org.example.sportdemo.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/groundPreserve")
public class GroundPreserveController {

    @Autowired
    private GroundPreserveService groundPreserveService;

    //分页
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params){

        PageUtils page = groundPreserveService.queryPage(params);

        R r = new R();
        r.put("page",page);
        return r;
    }

    //新增
    @RequestMapping(value = "/addGroundPreserve")
    public R addGroundPreserve(@RequestBody GroundPreserve groundPreserve){
        System.out.println(groundPreserve);
        groundPreserveService.addGroundPreserve(groundPreserve);
        return R.ok().put("groundPreserve",groundPreserve);
    }

    //修改
    @RequestMapping(value = "/updateGroundPreserve")
    public R updateGroundOrder(@RequestBody GroundPreserve groundPreserve){
        System.out.println(groundPreserve);
        groundPreserveService.updateGroundPreserve(groundPreserve);
        return R.ok().put("groundOrder",groundPreserve);
    }


    //根据id查询
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        GroundPreserve groundPreserve = groundPreserveService.selectById(id);
        return R.ok().put("groundPreserve",groundPreserve);
    }

    //删除
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        groundPreserveService.deleteByIds(ids);
        return R.ok();
    }

}
